import { EventManager } from "../../engine/EventManager";
import UIManager from "../../engine/UIManager";
import ViewBase from "../../engine/ViewBase";
import { EventConfig } from "../config/EventConfig";
import { ViewConfig } from "../config/ViewConfig";
import { UserModel } from "../model/UserModel";
import { UIHelper } from "../util/UIHelper";


const { ccclass, property } = cc._decorator;

@ccclass
export default class ViewMeilis extends ViewBase {

    onEnable(): void {
        super.onEnable()
        EventManager.instance.on(EventConfig.Event_Update_UserInfo, this.refresh, this)
        let btnExchange: cc.Node = this.findChild(this.node, "btnExchange")
        UIHelper.onAddEvent(btnExchange, () => {
            if (UserModel.instance.coins < 100000) {
                UIHelper.showTip("您的金豆不足10万,不能兑换")
            } else {
                UIManager.instance.showView(ViewConfig.viewConfig.ViewExchangeMeili)
            }
        })
        let btnUse: cc.Node = this.findChild(this.node, "btnUse")
        UIHelper.onAddEvent(btnUse, () => {
            UIHelper.showCheck("魅力值排行榜将于2023年上线,上榜可获得丰厚奖励，请注意积攒")
        })
        let btnGiveMeili: cc.Node = this.findChild(this.node, "btnGiveMeili")
        UIHelper.onAddEvent(btnGiveMeili, () => {
            UIManager.instance.showView(ViewConfig.viewConfig.ViewGiveMeili)
        })
        this.refresh()
    }

    private refresh() {
        let lbmeilis: cc.Label = this.getChild(this.node, "lbmeilis", cc.Label)
        lbmeilis.string = UserModel.instance.meilis + ""
        let lbcoins: cc.Label = this.getChild(this.node, "lbcoins", cc.Label)
        lbcoins.string = UserModel.instance.coins + ""
    }

}
